package com.kitty.game.player.serializer;

import com.kitty.game.player.model.PkInfoBox;
import com.kitty.game.role.model.Role;
import com.kitty.game.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;

public class PkInfoBoxSerializer implements IPlayerPropSerializer {

    @Override
    public void serialize(Role player) {
        if (player.getPkInfoBox() != null) {
            player.setPkInfoBoxJson(JsonUtils.object2String(player.getPkInfoBox()));
        }
    }

    @Override
    public void deserialize(Role player) {
        String json = player.getPkInfoBoxJson();
        if (StringUtils.isNotEmpty(json)) {
            player.setPkInfoBox(JsonUtils.string2Object(json, PkInfoBox.class));
        }
    }
}
